﻿@using OPM
@using OPM.MultiResource;
@model ContactAccount

@{
    Layout = "~/Views/Shared/_LayoutPopup.cshtml";
    var sl = new SL();
    var severities = sl.GetSeverity();
    var listPriorities = sl.GetPriority();
    var secrets = sl.GetSecret(); 
}

@using (Html.BeginForm("DuplicateCase", "GroupList", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="hidden" id="case_id" name="case_id" value="@Request["case_id"]" />
    <div class="service_search_header">
        <div class="service_title">@Multi.AddOperation</div>
    </div>

    <div class="service_search_header2">
        <div class="service_title">@Multi.TheContact</div>
    </div>

    <div class="service_box_table">
        <table id="service_table">
            <tr>
                <td>@Multi.date_opened</td>
                <td>
                    <table style="width:100%">
                        <tr>
                            <td style="width:56%">
                                <input type="text" name="date_opened" id="date_open" class="date-input"
                                       value="@(Model.cont_start.HasValue ?
                       Model.cont_start.Value.ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("en-US")) : "")" />
                                
                            </td>
                            <td style="width:4%"><span class="star">*</span></td>
                            <td style="width:20%">
                                <select name="hour" id="hour" class="date-time-input">
                                    @for (int i = 0; i < 24; i++)
                                    {
                                        <option value="@i"
                                                @(Model.cont_start.HasValue && Model.cont_start.Value.Hour == i ? "selected" : "")>
                                            @(i.ToString("00"))
                                        </option> 
                                    }
                                </select>
                            </td>
                            <td style="width:20%">
                                <select name="minute" id="minute" class="date-time-input">
                                    @for (int i = 0; i < 60; i++)
                                    {
                                        <option value="@i"
                                                @(Model.cont_start.HasValue && Model.cont_start.Value.Minute == i ? "selected" : "")>
                                            @(i.ToString("00"))
                                        </option> 
                                    }
                                </select>
                            </td>
                        </tr>
                    </table>
                    
                </td>
            </tr>
            <tr>
                <td>ช่องทางการติดต่อ</td>
                <td>
                    <a class="formBtn3 dBlock" data-block="lovchannelin"
                       href="@Url.Action("LovChannelIn")?a=lovchannelin&case_id=@Request["case_id"]"
                       onclick=" parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">@Multi.select_chanel</a>
                    <span id="block_chanel"></span>
                </td>
            </tr>
            <tr>
                <td>วัตถุประสงค์ของการติดต่อ</td>
                <td>
                    <a class="formBtn3 dBlock" data-block="lovobject"
                       href="@Url.Action("LovContactObj")?a=lovobject&case_id=@Request["case_id"]"
                       onclick=" parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">@Multi.objectivity</a>
                    <span id="block_obj"></span>
                </td>
            </tr>
            <tr>
                <td>@Multi.contact</td>
                <td>
           
                    <input type="text" id="cont_terminal_text" name="cont_terminal_text" value="" style="background-color: rgb(214, 214, 214)" readonly>
                    <input type="hidden" name="name-id" id="contact-id" value="" />

                    <input type="hidden" name="cont_cont_id" id="cont_cont_id" value="" />
                    <input type="hidden" name="cont_org_id" id="cont_org_id" value="" />

                    <input type="hidden" name="cont_is_secret" id="cont_is_secret" value="" />
                    <input type="hidden" name="cont_tel_all" id="cont_tel_all" value="" />
                    <input type="hidden" name="cont_country_id" id="cont_country_id" value="" />
                    <input type="hidden" name="cont_type" id="cont_type" value="" />
                    <input type="hidden" name="cont_gender_id" id="cont_gender_id" value="" />
                    <input type="hidden" name="cont_mobile_all" id="cont_mobile_all" value="" />
                    <input type="hidden" name="cont_title" id="cont_title" value="" />
                    <input type="hidden" name="cont_firstname" id="cont_firstname" value="" />
                    <input type="hidden" name="cont_lastname" id="cont_lastname" value="" />
                    <input type="hidden" name="cont_email_send_all" id="cont_email_send_all" value="" />
                    <input type="hidden" name="cont_citizen_id" id="cont_citizen_id" value="" />
                    <input type="hidden" name="cont_address" id="cont_address" value="" />
                    <input type="hidden" name="cont_province_id" id="cont_province_id" value="" />
                     <input type="hidden" name="cont_district_id" id="cont_district_id" value="" />
                    <input type="hidden" name="cont_subdistrict_id" id="cont_subdistrict_id" value="" />
                    <input type="hidden" name="cont_is_defective" id="cont_is_defective" value="" />
                    <input type="hidden" name="cont_postcode" id="cont_postcode" value="" />
                    <input type="hidden" name="cont_number" id="cont_number" value="" />
                    <input type="hidden" name="cont_remark" id="cont_remark" value="" />
                    <input type="hidden" name="cont_birthday" id="cont_birthday" value="" />
                    <input type="hidden" name="cont_contact_detail" id="cont_contact_detail" value="" />

                    @*<a href="@Url.Action("LovSearchContact", "Complaint")?a=contactadd&case_id=@Request["case_id"]"
                       data-block="block_contact" class="callBoxContact"
                       onclick=" parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">
                        <div class="search-person"></div>
                    </a>*@
                    <a href="@Url.Action("PopupAddContact", "Complaint")?a=contactInformation&case_id=@Request["case_id"]"
                       data-block="block_contact" class="callBoxContact"
                       onclick="parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">
                        <div class="search-person"></div>
                    </a>
                </td>
            </tr>
            <tr>
                <td>@Multi.contactHidden</td>
                <td>
                    <input type="checkbox" value="1" id="hidden-name-input" name="hidden-name-input"></td>
            </tr>
            <tr>
                <td>@Multi.is_secret</td>
                <td>

                    <select name="hour" id="cont_is_secret" class="date-time-input">
                        <option value="0">เปิดเผย</option>
                    </select>
                </td>
            </tr>
        </table>
    </div>	

    <div class="service_search_header2">
        <div class="service_title">@Multi.operation_type</div>
    </div>

    <div class="service_box_table">
       <table id="service_table">
            <tr>
                <td>@Multi.operationType</td>
                <td>
                    <a class="formBtn3 dBlock"  data-block="type"
                       href="@Url.Action("OperatingType")?a=type&case_id=@Request["case_id"]"
                           onclick="parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">@Multi.operationType</a>
                    <span id="block_type"></span> 
                </td>
            </tr>
            <tr>
                <td>@Multi.operatingStatus</td>
                <td><a class="formBtn3 dBlock" data-block="status"
                       href="@Url.Action("OperatingStatus")?a=status&case_id=@Request["case_id"]"
                       onclick="parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">@Multi.operatingStatus</a>
                    <span id="block_status"></span></td>
            </tr>
           @* <tr>
                <td>@Multi.recipient</td>
                <td> 
                    <input id="terminal_text" type="text" value="" name="terminal_text" style="background-color: rgb(214, 214, 214)" readonly>
                    <a href="@Url.Action("SelectTerminal", "GroupList")?a=contact&case_id=@Request["case_id"]" 
                       data-block="block_contact" class="callBoxContact" 
                       onclick="parent.callcolorboxrecursive($(this).attr('href'), getForm(), false); return false; ">
                        <div class="search-person"></div>
                        <input type="hidden" name="org_id" id="org_id" />
                        <input type="hidden" name="cont_id" id="cont_id" />
                    </a>
                </td>
            </tr>*@
            @*<tr>
                <td>@Multi.essence</td> 
                <td>
                    <textarea name="summary" id="summary" style="height: 40px">@Model.summary</textarea></td>
            </tr>*@
            <tr>
                <td>@Multi.detail</td>
                <td>
                    <textarea name="detail" id="detail" style="height: 60px">@Model.detail</textarea></td>
            </tr>
            <tr>
                <td>@Multi.file_input</td>
                <td>
                    <input type="file" name="file_input">
                </td>
            </tr>
            <tr>
                <td>@Multi.severity_id</td>
                <td>
                    @Html.DropDownListFor(m => m.severity_id, severities, "เลือกชั้นความเร่งด่วน", null)
                </td>
            </tr>
            <tr>
                <td>@Multi.secret_id</td>
                <td>
                    @Html.DropDownListFor(m => m.secret_id, secrets, "เลือกชั้นความลับ", null)
                </td>
            </tr>
            <tr>
                <td>@Multi.priority_id</td>
                <td>
                    @Html.DropDownListFor(m => m.priority_id, listPriorities, "เลือกชั้นความสำคัญ", null)
                </td>
            </tr>
           @if (!string.IsNullOrWhiteSpace(ViewBag.ErrorResult as string)) { 
           <tr>
               <td> </td>
               <td style="color:red">
                   @ViewBag.ErrorResult
               </td>
           </tr>
           }
        </table>
    </div>	

    <div class="BoxServiceBottom">
        <div class="BoxServiceActionPrev floatL" onclick="parent.$.fn.colorbox.close();">@Multi.Cancel</div>
        <input class="BoxServiceActionNext floatR" type="submit" value="@Multi.save_as">
        <div class="clear"></div>
    </div>	
}
<style>
    .formBtn3 {
        background-image: url('@Url.Content("~/images/form_button.png")');
        width: 180px;
        height: 24px;
        cursor: pointer;
        color: #726658;
        font-size: 0.85em;
        padding-left: 25px;
        padding-top: 7px;
        display: inline-block;
    }
</style>

<script>
    function getForm() {

        parent.formJson.case_id = '@Request["case_id"]';
        parent.formJson.type = $('#type').val();
        parent.formJson.type_text = $('#type_text').val();
        parent.formJson.status = $('#status').val();
        parent.formJson.status_text = $('#status_text').val();
        parent.formJson.cont_terminal_org_id = $('#cont_org_id').val();
        parent.formJson.cont_terminal_officer_id = $('#cont_cont_id').val();
        parent.formJson.cont_terminal_text = $('#cont_terminal_text').val();
        parent.formJson.type_text = $('#type_text').val();
        parent.formJson.date_open = $('#date_open').val();
        parent.formJson.hour = $('#hour').val();
        parent.formJson.minute = $('#minute').val();
        //formJson.summary = $('#summary').val();
        parent.formJson.detail = $('#detail').val(); 
        parent.formJson.objective_id = $('#lovobject').val();
        parent.formJson.objective_text = $('#lovobject_text').val();
        parent.formJson.channel_id = $('#lovchannelin').val();
        parent.formJson.channel_text = $('#lovchannelin_text').val();

        parent.formJson.terminal_org_id = $('#org_id').val();
        parent.formJson.terminal_officer_id = $('#cont_id').val();
        parent.formJson.terminal_text = $('#terminal_text').val();
        //$('#summary').val(parent.formJson.summary);
        parent.formJson.detail = $('#detail').val();
        parent.formJson.severity_id = $('#severity_id').val();
        parent.formJson.secret_id = $('#secret_id').val();
        parent.formJson.priority_id = $('#priority_id').val();

        parent.formJson.cont_is_secret = $('#cont_is_secret').val();
        parent.formJson.cont_tel_all = $('#cont_tel_all').val();
        parent.formJson.country_id = $('#cont_country_id').val();
        parent.formJson.cont_type = $('#cont_type').val();
        parent.formJson.cont_gender_id = $('#cont_gender_id').val();
        parent.formJson.cont_mobile_all = $('#cont_mobile_all').val();
        parent.formJson.cont_title = $('#cont_title').val();
        parent.formJson.cont_firstname = $('#cont_firstname').val();
        parent.formJson.cont_lastname = $('#cont_lastname').val();
        parent.formJson.cont_email_send_all = $('#cont_email_send_all').val();
        parent.formJson.cont_citizen_id = $('#cont_citizen_id').val();
        parent.formJson.cont_address = $('#cont_address').val();
        parent.formJson.locationToRedirect = $('#locationToRedirect').html();
        parent.formJson.province_id = $('#cont_province_id').val();
        parent.formJson.district_id = $('#cont_district_id').val();
        parent.formJson.subdistrict_id = $('#cont_subdistrict_id').val();
        parent.formJson.cont_is_defective = $('#cont_is_defective').val();
        parent.formJson.cont_postcode = $('#cont_postcode').val();
        parent.formJson.cont_number = $('#cont_number').val();
        parent.formJson.cont_remark = $('#cont_remark').val();
        parent.formJson.cont_birthday = $('#cont_birthday').val();
        parent.formJson.cont_contact_detail = $('#cont_contact_detail').val();

        return parent.formJson;
    }
    
    function genDivSelected(type, value, text) {
        var div1 = '<input type="hidden"  id="' + type + '" name="' + type + '" value="' + value + '">' +
            '<input type="hidden"  id="' + type + '_text" name="' + type + '_text" value="' + text + '">' +
                '<div class="blockReAction" data-value="'+value+'">' +
                    text + '<span onclick="removebox(\''+type+'\', '+value+');"></span>' +
                '</div>';
        console.log(text);
        //alert(div1);
        return div1;
    }
    $(document).ready(function () { 

        if (parent.formJson == null) {
            parent.formJson = new Object();
        }
         
        console.log(parent.formJson);
        if (parent.formJson.type) {
            var text2 = genDivSelected('type', parent.formJson.type, parent.formJson.type_text);
            $('#block_type').html(text2);
            console.log(text2);
        }
        if (parent.formJson.status) {
            var text3 = genDivSelected('status', parent.formJson.status, parent.formJson.status_text);
            $('#block_status').html(text3);
            console.log(text3);
        }

        if (parent.formJson.objective_id) {
            var text4 = genDivSelected('lovobject', parent.formJson.objective_id, parent.formJson.objective_text);
            $('#block_obj').html(text4);
            console.log(text4);
        }

        if (parent.formJson.channel_id) {
            var text5 = genDivSelected('lovchannelin', parent.formJson.channel_id, parent.formJson.channel_text);
            $('#block_chanel').html(text5);
            console.log(text5);
        }

        $('#org_id').val(parent.formJson.terminal_org_id);
        $('#cont_id').val(parent.formJson.terminal_officer_id);
        $('#terminal_text').val(parent.formJson.terminal_text);
        
        //$('#summary').val(parent.formJson.summary);
        $('#detail').val(parent.formJson.detail);
        $('#severity_id').val(parent.formJson.severity_id);
        $('#secret_id').val(parent.formJson.secret_id);
        $('#priority_id').val(parent.formJson.priority_id);
        $('#date_open').val(parent.formJson.date_open);
        $('#hour').val(parent.formJson.hour);
        $('#minute').val(parent.formJson.minute);

        $('#cont_terminal_text').val(parent.formJson.cont_terminal_text);
        $('#cont_cont_id').val(parent.formJson.cont_cont_id);
        $('#cont_org_id').val(parent.formJson.cont_org_id);

        $('#cont_is_secret').val(parent.formJson.cont_is_secret);
        $('#cont_tel_all').val(parent.formJson.cont_tel_all);
        $('#cont_country_id').val(parent.formJson.country_id);
        $('#cont_type').val(parent.formJson.cont_type);
        $('#cont_gender_id').val(parent.formJson.cont_gender_id);
        $('#cont_mobile_all').val(parent.formJson.cont_mobile_all);
        $('#cont_title').val(parent.formJson.cont_title);
        $('#cont_firstname').val(parent.formJson.cont_firstname);
        $('#cont_lastname').val(parent.formJson.cont_lastname);
        $('#cont_email_send_all').val(parent.formJson.cont_email_send_all);
        $('#cont_citizen_id').val(parent.formJson.cont_citizen_id);
        $('#cont_address').val(parent.formJson.cont_address);
        $('#locationToRedirect').html(parent.formJson.locationToRedirect);
        $('#cont_province_id').val(parent.formJson.province_id);
        $('#cont_district_id').val(parent.formJson.district_id);
        $('#cont_subdistrict_id').val(parent.formJson.subdistrict_id);
        $('#cont_is_defective').val(parent.formJson.cont_is_defective);
        $('#cont_postcode').val(parent.formJson.cont_postcode);
        $('#cont_number').val(parent.formJson.cont_number);
        $('#cont_remark').val(parent.formJson.cont_remark);
        $('#cont_birthday').val(parent.formJson.cont_birthday);
        $('#cont_contact_detail').val(parent.formJson.cont_contact_detail);
        $('#cont_terminal_text').val(emptyIfUndefined(parent.formJson.cont_title) +
            emptyIfUndefined(parent.formJson.cont_firstname) + '  ' + 
            emptyIfUndefined(parent.formJson.cont_lastname));
     
    });

    function emptyIfUndefined(v) {
        if (v == undefined) {
            return '';
        }
        return v;
    }
</script>
 